/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.app.common.material.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.collect.MapUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.common.idgen.IdGen;
import com.jeesite.modules.app.common.material.entity.AppCommonMaterial;
import com.jeesite.modules.app.common.material.service.AppCommonMaterialService;
import com.jeesite.modules.conf.AppController;
import com.jeesite.modules.conf.MessageCode;
import com.jeesite.modules.sys.utils.UserUtils;
import com.jeesite.modules.zx.common.material.entity.TcommonMaterial;
import com.jeesite.modules.zx.common.material.service.TcommonMaterialService;
import com.jeesite.common.web.BaseController;

/**
 * 公共资料Controller
 * @author zpp
 * @version 2020-02-14
 */
@Controller
@RequestMapping(value = "/app/common/material/")
public class AppCommonMaterialController {
    @Autowired
    private TcommonMaterialService tcommonMaterialService;
	@Autowired
	private AppCommonMaterialService appCommonMaterialService;
	@RequestMapping(value = "tfindPage")
	public void tfindPage(TcommonMaterial entity,HttpServletRequest request,HttpServletResponse response) {
		entity.setPage(new Page<>(request, response));
		Page<TcommonMaterial> findPage = tcommonMaterialService.findPage(entity);
		JSONObject json=JSONObject.parseObject(JsonMapper.toJson(findPage));
		AppController.renderSuccessObject(response, json, MessageCode.SUCCESS_ACK);
	}
	@RequestMapping(value = "findPage")
	public void findPage(AppCommonMaterial entity,HttpServletRequest request,HttpServletResponse response) {
		entity.setPage(new Page<>(request, response));
		entity.getSqlMap().getOrder().setOrderBy("id asc");
		Page<AppCommonMaterial> findPage = appCommonMaterialService.findPage(entity);
		JSONObject json=JSONObject.parseObject(JsonMapper.toJson(findPage));
		AppController.renderSuccessObject(response, json, MessageCode.SUCCESS_ACK);
	}
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public AppCommonMaterial get(String id, boolean isNewRecord) {
		return appCommonMaterialService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:common:material:tcommonMaterial:view")
	@RequestMapping(value = {"list", ""})
	public String list(AppCommonMaterial tcommonMaterial, Model model) {
		model.addAttribute("tcommonMaterial", tcommonMaterial);
		return "modules/zx/common/material/tcommonMaterialList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:common:material:tcommonMaterial:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public List<AppCommonMaterial> listData(AppCommonMaterial tcommonMaterial) {
		if (StringUtils.isBlank(tcommonMaterial.getParentCode())) {
			tcommonMaterial.setParentCode(AppCommonMaterial.ROOT_CODE);
		}
		if (StringUtils.isNotBlank(tcommonMaterial.getObjName())){
			tcommonMaterial.setParentCode(null);
		}
		if (StringUtils.isNotBlank(tcommonMaterial.getObjPicture())){
			tcommonMaterial.setParentCode(null);
		}
		if (tcommonMaterial.getObjType() != null){
			tcommonMaterial.setParentCode(null);
		}
		if (StringUtils.isNotBlank(tcommonMaterial.getRemarks())){
			tcommonMaterial.setParentCode(null);
		}
		if (tcommonMaterial.getObjExplain() != null){
			tcommonMaterial.setParentCode(null);
		}
		if (StringUtils.isNotBlank(tcommonMaterial.getObjAnswer())){
			tcommonMaterial.setParentCode(null);
		}
		List<AppCommonMaterial> list = appCommonMaterialService.findList(tcommonMaterial);
		return list;
	}

	
	
	
	
	
}